package ar.fiuba.logger;

import java.util.ArrayList;
import java.util.List;

import ar.fiuba.logger.filter.LogLevelLessThanOrEqualToThresholdFilter;
import ar.fiuba.logger.formatter.LogTextFormatter;
import ar.fiuba.logger.reporter.ConsoleReporter;

/**
 * The Class LogConfig.
 * 
 * This class is used to configure the logger.
 */
public class LogConfig {

  /** The separator. */
  public String separator;

  /** The format. */
  public String format;

  /** The log level. */
  public LogLevel threshold;

  /** The reporters. */
  public List<LogReporter> reporters = new ArrayList<LogReporter>();

  /** The filters. */
  public List<LogFilter> filters = new ArrayList<LogFilter>();

  /** The regex. */
  public String regex;

  /**
   * Instantiates a new log configuration with default values.
   */
  public LogConfig() {
    separator = "-";
    format = "%d{HH:mm:ss} ­ %p ­ %t ­ %m";
    threshold = LogLevel.TRACE;
    reporters = new ArrayList<LogReporter>();
    regex = "";

    LogFormatterInterface consoleReporterFormatter = new LogTextFormatter(format, separator);
    ConsoleReporter consoleReporter = new ConsoleReporter(consoleReporterFormatter);

    reporters.add(consoleReporter);

    filters.add(new LogLevelLessThanOrEqualToThresholdFilter(threshold));
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    LogConfig other = (LogConfig) obj;
    if (filters == null) {
      if (other.filters != null)
        return false;
    } else if (!filters.equals(other.filters))
      return false;
    if (format == null) {
      if (other.format != null)
        return false;
    } else if (!format.equals(other.format))
      return false;
    if (regex == null) {
      if (other.regex != null)
        return false;
    } else if (!regex.equals(other.regex))
      return false;
    if (reporters == null) {
      if (other.reporters != null)
        return false;
    } else if (!reporters.equals(other.reporters))
      return false;
    if (separator == null) {
      if (other.separator != null)
        return false;
    } else if (!separator.equals(other.separator))
      return false;
    if (threshold != other.threshold)
      return false;
    return true;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((filters == null) ? 0 : filters.hashCode());
    result = prime * result + ((format == null) ? 0 : format.hashCode());
    result = prime * result + ((regex == null) ? 0 : regex.hashCode());
    result = prime * result + ((reporters == null) ? 0 : reporters.hashCode());
    result = prime * result + ((separator == null) ? 0 : separator.hashCode());
    result = prime * result + ((threshold == null) ? 0 : threshold.hashCode());
    return result;
  }
}
